<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">关键字</label>
                    <div class="layui-input-inline">
                        <input type="text" name="info" placeholder="请输入关键字" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-app-contlist-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <table id="demo" lay-filter="demo"></table>
            <script type="text/html" id="table-content-list">
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">选择</a>
            </script>
        </div>
    </div>
</div>
<script src="/static/layuiadmin/layui/layui.js"></script>
<script>


    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table'], function(){
        var $ = layui.$,
                form = layui.form,
                table = layui.table;

        //监听搜索
        form.on('submit(LAY-app-contlist-search)', function(data){
            var field = data.field;
            //执行重载
            table.reload('demo', {
                url: "/admin/Common/page_list/type/{$type}",
                where: field,
                page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });

        //执行渲染
        table.render({
            elem: '#demo',
            url: "/admin/Common/page_list/type/{$type}",
            method: 'post',
            cols: [[
                {field: 'name', title: '标题(名称)', width: '80%', templet: function (d){ return d.name ? d.name : d.title; }},
                {fixed: 'right', title: '操作', align:'center', toolbar: '#table-content-list'}
            ]],
            page: {
                limits: [10, 20, 30, 40, 50]
            }
        });

        //监听事件
        table.on('tool(demo)', function(obj){
            var id = obj.data.id;
            var layEvent = obj.event;

            if(layEvent === 'edit'){ //编辑
                zhi1.val(zhi4 + '?id=' + id);
                zhi1.next().val(1);
                parent.parent.layer.close(zhi2);
                parent.layer.close(zhi3); //再执行关闭
            }
        });
    });


    var zhi1,zhi2,zhi3,zhi4;
    function child(can1, can2, can3, can4) {
        zhi1 = can1;
        zhi2 = can2;
        zhi3 = can3;
        zhi4 = can4;
    }
</script>
</body>
</html>
